from base.RunMethod import RunMethod
from configData.get_data import GetData
from util.comment import CommonUitl

class RunTest():
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.comm_Uitl = CommonUitl()


    #程序执行的
    def go_on_run(self):
        res = None
        rows_count = self.data.get_case_lines()#获取当前excel的行数

        for i in range(1,rows_count):
            #i=行数
            is_run = self.data.get_is_run(i)
            print(i)
            if is_run==True:
                    url = self.data.get_request_url(i)#获取excel url
                    method = self.data.get_request_method(i)#获取excel data
                    data = self.data.get_data_for_json(i)#通过关键字从json中获取资料
                    headers = self.data.is_header(i)#获取excel hearders
                    expect = self.data.get_expect_data(i)#预期结果数值
                    print(expect)
                    res = self.run_method.run_main(url=url,method=method,data=data,headers=headers)#执行RunMethod类的方法
                    if self.comm_Uitl.is_contain(expect,res):
                        print("Test is Good!")
                    else:
                        print("Test is Fail!")

                    #使用TRY的方法去修改
            print(res)



if __name__=="__main__":
    run = RunTest()
    print(run.go_on_run())
